package A04_链表.A41_单向链表;

/**
 * @Author: KingWang
 * @Date: 2021/5/30
 * @Desc:
 **/
public class LinkedList {

    private LinkedNode head = new LinkedNode(0,"head");

    public void add(LinkedNode node){
        //首先要找到链表的最后一个，然后添加一个引用
        //如果找到最后一个：判断next是否为空
        //如果为空，则继续查找下一个，否则添加引用
        LinkedNode tempNode = head;
        while(true){
            if(tempNode.getNext() == null) {
                break;
            }
           tempNode = tempNode.getNext();
        }
        tempNode.setNext(node);
    }

    public void show(){
        if(null == head.getNext()){
            System.out.println("链表为空");
        }

        LinkedNode  temp = head;
        while(null != temp.getNext()){
            System.out.println(temp.toString());
            temp = temp.getNext();
        }
    }

    public void print(){
        StringBuilder sb = new StringBuilder();
        if(null == head.getNext()){
            System.out.println("链表为空");
        }

        LinkedNode  temp = head;
        while(null != temp.getNext()){
            sb.append(temp.getValue() + "->");
            temp = temp.getNext();
        }

        System.out.println(sb.toString());
    }

    public void remove(int id){
        LinkedNode prefixNode = head;
        LinkedNode suffixNode = head;
        LinkedNode temp = head;

        while(true){
            if(null != temp.getNext()){

                if(id != temp.getNext().getId()){

                    prefixNode = temp;


                }


            }
        }


    }


}
